// API 响应基础类型
export type BaseResponse<T> = {
  code: number | string; // 支持数字和字符串格式
  message?: string;
  msg?: string; // 有些API使用msg字段
  data: T;
  type?: number; // 额外的type字段
  time?: number; // 时间戳字段
};

// 用户相关类型
export type UserInfo = {
  userId: number;
  agencyId: number;
  roles: string[];
  mobile: string;
  nickName: string;
  realName: string;
  avatar: string;
  language: string | null;
};

// 钱包相关类型
export type WalletInfo = {
  balance: number;
  currency: string;
  depositAmount?: number;
  depositStatus?: string;
};

// 登录相关类型
export type LoginRequest = {
  code?: string;
  phone?: string;
  email?: string;
  msgCode: string;
  password?: string;
};

export type MobileLoginRequest = {
  countryCode: string;
  phoneNumber: string;
  securityCode: string;
};

export type SendCodeRequest = {
  countryCode: string;
  phoneNumber: string;
  type: 'login' | 'register' | 'binding' | 'invite';
};

// 注册相关类型
export type RegisterRequest = {
  countryCode: string;
  phoneNumber: string;
  securityCode: string;
  password?: string;
  inviteCode?: string;
};

// 租借柜相关类型
export type RentboxInfo = {
  id: string;
  name: string;
  location: string;
  lat: number;
  lng: number;
  status: 'available' | 'busy' | 'maintenance';
  availableCount: number;
  totalCount: number;
};

export type RentboxOrder = {
  id: string;
  rentboxId: string;
  rentboxName: string;
  startTime: string;
  endTime?: string;
  status: 'renting' | 'returned' | 'overdue';
  amount: number;
  depositAmount: number;
};

// 订单相关类型
export type OrderInfo = {
  id: string;
  type: 'rent' | 'deposit' | 'refund';
  amount: number;
  status: 'pending' | 'paid' | 'failed' | 'refunded';
  createTime: string;
  payTime?: string;
  description?: string;
};

// 支付相关类型
export type PaymentRequest = {
  orderId: string;
  amount: number;
  paymentMethod: 'wechat' | 'alipay' | 'stripe' | 'omise' | 'paypal' | 'iyzipay' | 'razorpay' | 'vnpay' | 'momopay' | 'zalopay';
  returnUrl?: string;
};

export type PaymentResponse = {
  paymentUrl?: string;
  paymentData?: any;
  orderId: string;
};

// 优惠券相关类型
export type CouponInfo = {
  id: string;
  name: string;
  description: string;
  discountType: 'amount' | 'percentage';
  discountValue: number;
  minAmount?: number;
  validFrom: string;
  validTo: string;
  status: 'available' | 'used' | 'expired';
};

// 网点相关类型
export type SiteInfo = {
  id: number;
  lng: number;
  lat: number;
  name: string;
  address: string;
  open_time: string;
  powerbank_type: number;
  distance: number;
  distanceCn: string;
  open: boolean;
  borrow: boolean;
  empty: boolean;
  depotEmpty?: number; // 空置充电宝数量
  depotBorrow?: number; // 可借充电宝数量
  tel?: string; // 联系电话
};

// 网点查询参数类型
export type SiteListRequest = {
  lng: number;
  lat: number;
  distance?: number;
  total?: number;
};

// 银行卡相关类型
export type PaymentCard = {
  id: string;
  cardNumber: string;
  cardType: string;
  expiryDate: string;
  holderName: string;
  isDefault: boolean;
};

// 广告相关类型
export type AdvertInfo = {
  id: string;
  title: string;
  image: string;
  link?: string;
  type: 'banner' | 'popup' | 'inline';
  position: string;
};

// 白名单相关类型
export type WhitelistUser = {
  id: string;
  phone: string;
  name: string;
  inviteCode: string;
  status: 'active' | 'inactive';
  createTime: string;
};

// 页面数据相关类型
export type PageData = {
  title: string;
  content: string;
  images?: string[];
  links?: Array<{ text: string; url: string }>;
};

// 扫码相关类型
export type ScanResult = {
  deviceId: string;
  cabinetSN: string;
  qrCode: string;
  isValid: boolean;
  deviceInfo?: DeviceInfo;
};

export type DeviceInfo = {
  id: string;
  name: string;
  location: string;
  lat: number;
  lng: number;
  status: 'available' | 'busy' | 'maintenance' | 'offline';
  availableCount: number;
  totalCount: number;
  powerbankType: number;
  openTime: string;
  distance?: number;
  distanceCn?: string;
  originalData?: {
    rentbox: any;
    config: any;
    userCoupons: any[];
    ADList: any[];
    mob: string;
    type: boolean;
    discountTime: number;
  };
};

// 租借相关类型
export type RentalRequest = {
  deviceId: string;
  cabinetSN: string;
  powerbankType?: number;
};

export type RentalResponse = {
  orderId: string;
  deviceId: string;
  deviceName: string;
  powerbankType: number;
  depositAmount: number;
  billingRules: BillingRule[];
  status: 'success' | 'failed';
  message?: string;
};

export type BillingRule = {
  description: string;
  amount: number;
  timeLimit?: number;
};

// 扫码验证请求
export type ScanValidationRequest = {
  qrCode: string;
  cabinetSN?: string;
};

export type ScanValidationResponse = {
  isValid: boolean;
  deviceInfo?: DeviceInfo;
  message?: string;
};

// 用户中心数据类型 - 简化版本，只存储user数据
export type UserCenterUser = {
  id: number;
  nickName: string;
  realName: string;
  sex: number;
  avatar: string;
  email: string;
  loginName: string;
  loginType: string;
  password: string;
  salt: string;
  score: number;
  level: number;
  vip: number;
  countryCode: number;
  mobile: string;
  tel: string;
  qq: string;
  wechat: string;
  balanceFee: number;
  securityFee: number;
  securityFree: boolean;
  securityOrderId: number;
  wxSecurityOrderId: number;
  currencyCode: string;
  bean: number;
  nation: string;
  province: string;
  city: string;
  area: string;
  birthday: string | null;
  remark: string;
  real: boolean;
  signed: boolean;
  agencyId: number;
  staffUid: number;
  tryCount: number;
  disabled: boolean;
  del: boolean;
  inviteUid: number;
  createUid: number;
  createTime: number;
  updateTime: number;
  joinDate: string | null;
  relativeProfitSharing: boolean;
  profitProportion: number;
  phoneNumberVerification: boolean;
  businessCommission: number;
  incentivePayment: number;
  userTag: string;
  openId: string;
};

// 简化的用户中心数据，只包含user字段
export type UserCenterData = {
  user: UserCenterUser;
};
